package shuaige.jdk.多线程.锁.可重入锁;

import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLock_可重入性 {

    public static void main(String[] args) throws InterruptedException {
        可重入性测试();
    }

    public static void 可重入性测试() {
        ReentrantLock lock = new ReentrantLock();

        for (int i = 1; i <= 3; i++) {
            lock.lock();
            System.out.println("lock:" + i);
        }

        for (int i = 1; i <= 3; i++) {
            try {

            } finally {
                if (i != 2) {
                    System.out.println("unlocak:" + i);
                    lock.unlock();
                }
            }
        }
    }

}
